package com.gaofeng.day07;

import java.util.*;

public class demo1 {
    public static void main(String[] args) {
        String[] arr = {"A", "B", "C", "D"};

        ArrayList<String> list = new ArrayList<>();

        Random rd = new Random();
        for (int i = 0; i < 80; i++) {
            int index = rd.nextInt(arr.length);
//            System.out.println(arr[index]);
            list.add(arr[index]);
        }

        HashMap<String, Integer> hm = new HashMap<>();
        for (String item : list) {
            if (hm.containsKey(item)) {
                int count = hm.get(item);
                hm.put(item, ++count);
            } else {
                hm.put(item, 1);
            }
        }
        System.out.println(hm);

        //求最大值
        int max = 0;

        Set<Map.Entry<String, Integer>> entries = hm.entrySet();
        for (Map.Entry<String, Integer> entry : entries) {
            int count = entry.getValue();
            System.out.println(count);
            if(count > max){
                max = count;
            }
        }
        System.out.println(max);

        for (Map.Entry<String, Integer> entry : entries) {
            int count = entry.getValue();
            if(max == count){
                System.out.println(entry.getKey());
            }
        }
    }
}
